import * as actionTypes from '../actions/ActionTypes';

import {handleActions} from 'redux-actions';


const defData = {
    msgList: []
}

export const SelSystemNewsReducer = handleActions({
    [actionTypes.SEL_MSGALL_MOB]: {
        next(state, action) {
            if (action.payload.page != 1) {//不是第一页时追加msgList
                action.payload.msgList = state.data.msgList.concat(action.payload.msgList);
            }
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, data: defData};
        }
    }, [actionTypes.DELETEBYIDMOB]: {
        next(state, action) {
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, data: defData};
        }
    }, [actionTypes.ISREAD_BYID]: {
        next(state, action) {
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, data: defData};
        }
    }
}, {ret: true, isloading: true, data: defData});

//20171216-王继顺
//企业首页-查询信息
const defData88 = {
    msgList: []
};
export const SelComMsgAllReducer = handleActions({
    [actionTypes.SEL_COM_MSGALL_MOB]: {
        next(state, action) {
            if (action.payload.page !== 1) {//不是第一页时追加msgList
                action.payload.msgList = state.data.msgList.concat(action.payload.msgList);
            }
            return {ret: true, isloading: false, data: action.payload};
        },
        throw() {
            return {ret: false, isloading: false, data: defData88};
        }
    }, [actionTypes.DELETEBYIDMOB]: {
        next(state, action) {
            return {ret: true, isloading: false, data: action.payload};
        },
        throw() {
            return {ret: false, isloading: false, data: defData};
        }
    }, [actionTypes.ISREAD_BYID]: {
        next(state, action) {
            return {ret: true, isloading: false, data: action.payload};
        },
        throw() {
            return {ret: false, isloading: false, data: defData};
        }
    }
}, {ret: true, isloading: true, data: defData88});


const defData2 = {
    postionBrowseList: []
}
export const SelBrowseHistoryReducer = handleActions({
    [actionTypes.SEL_BROWSE_HISTORY]: {
        next(state, action) {
            if (action.payload.page != 1) {//不是第一页时追加postionBrowseList
                action.payload.postionBrowseList = state.data.postionBrowseList.concat(action.payload.postionBrowseList);
            }
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, data: defData2};
        }
    }
}, {ret: true, isloading: true, data: defData2});


const defData3 = {
    msgList: []
}
export const SelCollectPositionReducer = handleActions({
    [actionTypes.SEL_COLLECT_POSITION]: {
        next(state, action) {
            if (action.payload.page != 1) {//不是第一页时追加msgList
                action.payload.msgList = state.data.msgList.concat(action.payload.msgList);
            }
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, data: defData};
        }
    }
}, {ret: true, isloading: true, data: defData});

//我的简历
const defData4 = {
    resume: {},
    msg: '',
    isloading: true//是否读取ing1
}

export const EditResumeReducer = handleActions({
    //查询个人简历
    [actionTypes.EDIT_RESUME]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData4};
        }
    },
    //修改个人简历
    [actionTypes.UPDATE_RESUME]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData4};
        }
    },
    //修改工作经历
    [actionTypes.UPDATE_JOBEXP]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData4};
        }
    },
    //添加工作经历
    [actionTypes.INSERT_JOBEXP]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData4};
        }
    },
    //添加教育经历
    [actionTypes.INSERT_EDUCATION]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData4};
        }
    },
    //修改教育经历
    [actionTypes.UPDATE_EDUCATION]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData4};
        }
    },
    //添加项目经历
    [actionTypes.INSERT_PROJECTEXP]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData4};
        }
    },
    //修改项目经历
    [actionTypes.UPDATE_PROJECTEXP]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData4};
        }
    }
}, {ret: true, statusText: '默认', data: defData4});

//我的消息
const defData5 = {
    member: {},
    isloading: true//是否读取ing1
}

export const MemberInfoReducer = handleActions({
    [actionTypes.SEL_MEMBERINFO_MOB]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData5};
        }
    }
}, {ret: true, statusText: '默认', data: defData5});

//修改我的消息
const defData6 = {
    member: {},
    isloading: true//是否读取ing1
}

export const updateMemberInfoReducer = handleActions({
    [actionTypes.UPDATE_MEMBERINFO]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData6};
        }
    }
}, {ret: true, statusText: '默认', data: defData6});

//查询行业
const defData7 = {
    fieldList: []
}
export const SelFieldTypeReducer = handleActions({
    [actionTypes.SELFIELD_BYTYPE]: {
        next(state, action) {
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, data: defData7};
        }
    }
}, {ret: true, isloading: true, data: defData7});

//修改密码
const defData8 = {
    msg: {},
    isloading: true//是否读取ing1
}
export const UpdatePasswordReducer = handleActions({
    [actionTypes.UPDATE_PASSWORD]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData8};
        }
    }
}, {ret: true, statusText: '默认', data: defData8});

//发送邮箱验证码
const defData9 = {
    msg: {},
    isloading: true//是否读取ing1
}
export const RegisterSendEReducer = handleActions({
    [actionTypes.REGISTER_SENDE]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData9};
        }
    },
    [actionTypes.REGISTER_SENDE_YZ]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData9};
        }
    }
}, {ret: true, statusText: '默认', data: defData9});

//发送邮箱验证码
const defData10 = {
    msg: {},
    isloading: true//是否读取ing1
}
export const SelxzLonginReducer = handleActions({
    [actionTypes.SEL_XZLOGIN]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData10};
        }
    }
}, {ret: true, statusText: '默认', data: defData10});

//修改手机
const defData11 = {
    msg: {},
    isloading: true//是否读取ing1
}
export const UpdataPReducer = handleActions({
    [actionTypes.UPDATE_PHONE]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData11};
        }
    }
}, {ret: true, statusText: '默认', data: defData11});

//意见反馈
const defData12 = {
    msg: {},
    isloading: true//是否读取ing1
}
export const SendIdeaReducer = handleActions({
    [actionTypes.SEND_IDEA]: {
        next(state, action) {
            return {ret: true, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, statusText: "报错", data: defData12};
        }
    }
}, {ret: true, statusText: '默认', data: defData12});